package org.jjche.sys.modules.system.mapper;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jjche.mybatis.base.MyBaseMapper;
import org.jjche.sys.modules.system.domain.DeptDO;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>UserMapStruct interface.</p>
 *
 * @author Zheng Jie
 * @version 1.0.8-SNAPSHOT
 * @since 2018-11-22
 */
public interface DeptMapper extends MyBaseMapper<DeptDO> {
    /**
     * 根据角色ID 查询
     *
     * @param roleId 角色ID
     * @return /
     */
    List<DeptDO> selectByRoleId(Long roleId);

    /**
     * <p>
     * 获取最大值code的部门信息
     * </p>
     *
     * @param pid 上级id
     * @return /
     */
    DeptDO getMaxCodeDept(String pid);

    /**
     * <p>
     * 查询ids根据编码
     * </p>
     *
     * @param deptCodes
     * @return /
     */
    default Set<Long> listIdsByCodes(Set<String> deptCodes) {
        if (CollUtil.isNotEmpty(deptCodes)) {
            LambdaQueryWrapper<DeptDO> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.select(DeptDO::getId);
            queryWrapper.in(DeptDO::getCode, deptCodes);
            return this.selectObjs(queryWrapper).stream().map(intValue -> Long.valueOf(intValue.toString())).collect(Collectors.toSet());
        }
        return null;
    }
}
